package com.yjs.app.trade.service.service.sys.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yjs.app.trade.core.util.StringUtils;
import com.yjs.app.trade.service.mapper.sys.UserMapper;
import com.yjs.app.trade.service.service.sys.UserService;
import com.yjs.business.ecps.order.service.IUserService;

@Service("uService")
public class UserServiceImpl implements UserService {

	@Autowired
	UserMapper userMapper;
	
	@Autowired
	IUserService iUserService;
	
	@Override
	public Map<String, Object> getUserInfo(String passportId) {
		Map<String, Object> map = userMapper.getUserInfo(passportId);
		for (Map.Entry<String, Object> entry : map.entrySet()) {
			if (StringUtils.equals("mobile", entry.getKey())) {
				map.put("mobile", entry.getValue().toString().replace(entry.getValue().toString().substring(3, 7), "****"));
			}
		}
		return userMapper.getUserInfo(passportId);
	}

	@Override
	@Transactional
	public int updateUserPhoto(String passportId, String photoUrl) {
		/*Map<String, Object> map = new HashMap<>();
		map.put("passportId", passportId);
		map.put("photo", photoUrl);
		return userMapper.updateUserPhoto(map);*/
		return iUserService.updateUserPhoto(passportId, photoUrl);
	}

	@Override
	@Transactional
	public int updateUserPhone(String passportId, String phoneNumber) {
		/*Map<String,Object> map=new HashMap<String,Object>();
		map.put("passportId", passportId);
		map.put("phoneNumber", phoneNumber);
		int result = userMapper.updateUserInfo(map);
		return result;*/
		return iUserService.updateUserPhone(passportId, phoneNumber);
	}

	@Override
	@Transactional
	public int updateUserEmail(String passportId, String email) {
		/*Map<String,Object> map=new HashMap<String,Object>();
		map.put("passportId", passportId);
		map.put("email", email);
		int result = userMapper.updateUserInfo(map);
		return result;*/
		return iUserService.updateUserEmail(passportId, email);
	}

	@Override
	@Transactional
	public int updateUserRegion(String passportId, String provinceRegionId, String cityRegionId, String countyRegionId, String address) {
		/*Map<String, Object> map = new HashMap<String, Object>();
		map.put("passportId", passportId);
		map.put("provinceRegionId", provinceRegionId);
		map.put("cityRegionId", cityRegionId);
		map.put("countyRegionId", countyRegionId);
		map.put("address", address);
		return userMapper.updateUserRegion(map);*/
		return iUserService.updateUserRegion(passportId, provinceRegionId, cityRegionId, countyRegionId, address);
	}
	
	@Override
	@Transactional
	public int updateLoginMac(String passportId, String mac) {
		/*Map<String, Object> map = new HashMap<>();
		map.put("passportId", passportId);
		map.put("mac", mac);
		return userMapper.updateUserMac(map);*/
		return iUserService.updateLoginMac(passportId, mac);
	}

	@Override
	public Object getUserRole(String memberId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object updateIdentityAuthentication(String passportId, String name, String idcardno) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object updateUserPassword(String oldPwd, String newPwd) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object checkUserPassword(String oldPwd) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getUserAuthentication(Map<String, Object> map) {
		return userMapper.getUserAuthentication(map);
	}

	@Override
	@Transactional
	public void updateIdEntification(Map<String, Object> map) {
		/*userMapper.updateIdEntification(map);*/
		iUserService.updateIdEntification(map);
	}

	@Override
	@Transactional
	public int updateUserMobile(String passportId, String mobile) {
		/*Map<String,Object> map=new HashMap<String,Object>();
		map.put("passportId", passportId);
		map.put("mobile", mobile);
		int result = userMapper.updateUserInfo(map);
		return result;*/
		return iUserService.updateUserMobile(passportId, mobile);
	}

	@Override
	public List<Map<String, Object>> findPassportIdByMemberId(Map<String, Object> param) {
		return userMapper.findPassportIdByMemberId(param);
	}

	@Override
	public List<String> getUserId(Map<String, Object> map) {
		return userMapper.getUserId(map);
	}

	@Override
	public int updateUserInfo(Map<String,Object> map) {
		return iUserService.updateUserInfo(map);
	}

	@Override
	public List<Map<String, Object>> getPassportSalesAut(String passportId) {
		return userMapper.getPassportSalesAut(passportId);
	}
	
	@Override
	public boolean isManagerPassport(String passportId) {
		Map<String, Object> user = this.getUserInfo(passportId);
		if (StringUtils.strIsNotNull(user.get("adminPassportId"))) {
			return true;
		} else {
			return false;
		}
	}
}
